// pages/master/mainten/famMainten/childMedHistory/childMedHistory.js
var historyDB=wx.cloud.database().collection('childMedicalHistory')
const app = getApp();
const db = wx.cloud.database()
const _ = db.command

Page({

  /**
   * 页面的初始数据
   */
  data: {
    historyList:[],
    startDate:'0000-00-00',
     endDate :'0000-00-00',
     FamilyNum:null,
     ChildName:null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
console.log(options)
//famnum='0001'&childName='张大宝'
historyDB.where({
  FamilyNum:options.famnum,//'0001',
  ChildName:options.childName//'张大宝'
}).orderBy('date', 'desc').get().then(res=>{
    console.log(res)
    that.setData({
      FamilyNum:options.famnum,
      ChildName:options.childName,
        historyList:res.data
    })
})
  },
  previewImage: function (e) {
    app.previewImage(e)
  },

  addhistory:function(){
      wx.navigateTo({
        url: './addHistory/addHistory?famnum='+this.data.FamilyNum+'&childName='+this.data.ChildName,
      })
  },
  clickSearch:function(e){
      console.log(e)
      let that = this
      let startDate = e.detail.value.sdate
      let endDate = e.detail.value.edate
      if(startDate==''||endDate==""){
          wx.showToast({
            title: '请选择时间范围',
            icon:'none'
          })
      }else{ 
      let fnum = that.data.FamilyNum 
      let cnum = that.data.ChildName
      historyDB.where({
        FamilyNum:fnum,//'0001',
        ChildName:cnum,//'张大宝'
        date: _.gte(startDate).and(_.lte(endDate))
      }).orderBy('date', 'desc').get().then(res=>{
          console.log(res)
          that.setData({
              historyList:res.data
          })
      })
    }
  },
  pickStartDate:function(e){
    //console.log(e.detail.value)
    this.setData({
      startDate:e.detail.value
    })
  },
  pickEndDate:function(e){
    this.setData({
      endDate:e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})